//
//  GGNetWorkConnector.m
//  QuickAskCommunity
//
//  Created by yuemei on 2018/2/6.
//  Copyright © 2018年 ym. All rights reserved.
//

#import "GGNetWorkConnector.h"


@interface AFHTTPSessionManager()

- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
                                       URLString:(NSString *)URLString
                                      parameters:(id)parameters
                                         success:(void (^)(NSURLSessionDataTask *, id))success
                                         failure:(void (^)(NSURLSessionDataTask *, NSError *))failure;
@end


@implementation GGNetWorkConnector

+ (instancetype)sharedConnector{
    static GGNetWorkConnector *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        
        NSURLSessionConfiguration *congfig = [NSURLSessionConfiguration defaultSessionConfiguration];
        congfig.timeoutIntervalForRequest = 26;
        instance = [[self alloc] initWithSessionConfiguration:congfig];
        //        instance = [[self alloc] initWithBaseURL:baseUrl sessionConfiguration:congfig];
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    });
    return instance;
}

- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
                                      URLString:(NSString *)URLString
                                     parameters:(id)parameters
                                        success:(void (^)(NSURLSessionDataTask *, id))success
                                        failure:(void (^)(NSURLSessionDataTask *, NSError *))failure{
    
    
    return [super dataTaskWithHTTPMethod:method URLString:URLString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject){
        if (responseObject == nil || [responseObject count] == 0) {
            failure(task,[NSError errorWithDomain:CODE_INFO code:GGResponseResultTypeRequestDataFormatError userInfo:@{@"task":task}]);
            return ;
        }
        success(task,responseObject);
    } failure:failure];
    
    
}
@end
